package kis.io.xml.bysocket.apply;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class SocketClient extends Thread
{
	private ServerSocket client = null;

	public SocketClient(ServerSocket client)
	{
		try
		{
			if (null == client)
			{
				this.client = new ServerSocket(8099);
				System.out.println("socket start");
			}
		} catch (Exception e)
		{
			System.out.println("创建serverSocket出错");
		}
	}

	public void run()
	{
		while (!this.isInterrupted())
		{
			try
			{
				Socket socket = client.accept();

				if (null != socket && !socket.isClosed())
				{
					new Thread(new HandlerThread(socket)).start();
				}
				socket.setSoTimeout(60 * 1000);

			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}
	}

	public void closeSocketServer()
	{
		try
		{
			if (null != client && !client.isClosed())
			{
				client.close();
			}
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
